package com.suray.basic.wcs.plc.pojo.oper;

import com.suray.basic.wcs.plc.config.resolver.PlcAnnotation;
import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;
import com.suray.basic.wcs.utils.LoggerUtil;

import java.io.IOException;

/**
 * @author shaozn
 * @date 2020/1/22 - 14:02
 * @Description 移栽机监控对象
 */
public class TransplanterOper extends DeviceBase {
    private static final PlcOffset PALLET_NO = new PlcOffset(0, null);
    private static final PlcOffset PALLET_EXIST = new PlcOffset(1, 8);
    private static final PlcOffset RUN_STATUS = new PlcOffset(1, 9);
    private static final PlcOffset IS_ERROR = new PlcOffset(1, 10);
    private static final PlcOffset RUN_STATUS_2 = new PlcOffset(1, 11);
    private static final PlcOffset IS_ERROR_2 = new PlcOffset(1, 12);
    private static final PlcOffset UPPER_LIMIT = new PlcOffset(1, 13);
    private static final PlcOffset LOWER_LIMIT = new PlcOffset(1, 14);

    /**
     * 移栽机托盘编号
     */
    private Integer palletNo;

    /**
     * 工位是否有货
     */
    private boolean palletExist;
    /**
     * 工位运行状态
     */
    private boolean runStatus;
    /**
     * 工位故障
     */
    private boolean isError;
    /**
     * 工位运行状态
     */
    private boolean runStatus2;
    /**
     * 工位故障
     */
    private boolean isError2;
    /**
     * 工位运行状态
     */
    private boolean upperLimit;
    /**
     * 工位故障
     */
    private boolean lowerLimit;

    public TransplanterOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                            Location location, Coord lockLocation, long deviceId, Integer gridzMax,
                            Integer gridzRelative, int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation,deviceId,gridzMax,
                gridzRelative, plcId);
    }

    public Integer getPalletNo() {
        return readPlc(PALLET_NO);
    }

    public boolean isPalletExist() {
        return readPlc(PALLET_EXIST) == 1;
    }

    public boolean isRunStatus() {
        return readPlc(RUN_STATUS) == 1;
    }

    public boolean isError() {
        return readPlc(IS_ERROR) == 1;
    }

    public boolean isRunStatus2() {
        return readPlc(RUN_STATUS_2) == 1;
    }

    public boolean isError2() {
        return readPlc(IS_ERROR_2) == 1;
    }

    public boolean isUpperLimit() {
        return readPlc(UPPER_LIMIT) == 1;
    }

    public boolean isLowerLimit() {
        return readPlc(LOWER_LIMIT) == 1;
    }
}
